package AutoTest;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-09-04
 * Time: 23:39
 */
public class AutoFun {
    private static WebDriver driver=null;
    public static WebDriver getDriver(){
        if(driver==null) {
            WebDriverManager.chromedriver().setup();           //管理驱动
            ChromeOptions options = new ChromeOptions();         //浏览器配置类
            options.addArguments("--remote-allow-origins=*");  //允许访问所有链接
            driver = new ChromeDriver(options);
            driver.manage().window().maximize();
        }
        return driver;
    }
    public static WebDriver getDriver(String str){
        if(driver==null) {
            WebDriverManager.chromedriver().setup();           //管理驱动
            ChromeOptions options = new ChromeOptions();         //浏览器配置类
            options.addArguments("--remote-allow-origins=*");  //允许访问所有链接
            driver = new ChromeDriver(options);
            driver.manage().window().maximize();
        }
        driver.get(str);                                       //访问链接
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
        return driver;
    }

}
